package com.game.modular.game.battle.panel;

import cn.hutool.extra.spring.SpringUtil;
import com.game.comment.util.RedisUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
import java.util.concurrent.TimeUnit;

import static com.game.modular.game.battle.info.FiledName.eventMap;
import static com.game.modular.game.battle.info.FiledName.phaseMap;

/**
 * 战斗流程
 */
@Slf4j
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Battle implements Serializable {
    @ApiModelProperty("战斗id")
    private Long battleId;
    @ApiModelProperty("当前回合数")
    private Integer round;
    @ApiModelProperty("当前阶段 ")
    private Integer phase;
    @ApiModelProperty("当前事件")
    private Integer event;

    public void save() {
        RedisUtils redisUtils = SpringUtil.getBean(RedisUtils.class);
        redisUtils.set("battle:" + battleId + ":", this, 30L, TimeUnit.MINUTES);
    }

    public static Battle get(Long battleId) {
        RedisUtils redisUtils = SpringUtil.getBean(RedisUtils.class);
        return (Battle) redisUtils.get("battle:" + battleId + ":");
    }

    public void logBattle() {
        log.info("=========================" +
                        "-战斗编号:{} " +
                        "========================="
                , battleId
        );
    }


    public void logPhase() {
        log.info("-------------------------{}:{}阶段-------------------------",
                phase, phaseMap.get(phase)
        );
    }


    public void logEvent() {
        log.info("--------------------{}:事件:{}",
                event, eventMap.get(event)
        );
    }


}